package com.sixth.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sixth.dao.StafftransferDao;
import com.sixth.entity.Staff;
import com.sixth.entity.Stafftransfer;
import com.sixth.service.StafftransferService;
import com.sixth.util.CommonResult;
import com.sixth.util.TableLayUi;
import com.sixth.util.WebUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @program: project01
 * @description:
 * @author: 高振杨
 * @create: 2021-12-20 16:19
 **/
@Service(value = "stafftransferserviceImpl")
public class StafftransferServiceImpl implements StafftransferService {

    @Autowired
    private StafftransferDao dao;
    public CommonResult transferstaff(Integer staffid, Integer branchid, Integer deptid, Integer newbranchid, Integer newdeptid, Date applytime, Integer applyid, Integer state) {
        Staff staff = (Staff) WebUtil.getSession().getAttribute("staff");
        applyid=staff.getStaffid();

        Date date = new Date();
        applytime=date;
        int i = dao.insertByContent(staffid,branchid,deptid,newbranchid,newdeptid,applytime,applyid,state);
        if (i>0){
            return new CommonResult(2000,"调动已提交",null);
        }
        return new CommonResult(5000,"调动提交失败",null);

    }

    @Override
    public CommonResult geteditIngstaff(Integer staffid) {
        Stafftransfer stafftransfer=dao.geteditIngstaff(staffid);
        if (stafftransfer==null){
            return new CommonResult(0,"该员工没有在调职状态",null);
        }
        return new CommonResult(2,"该员工在调职状态",null);
    }

    public TableLayUi findAll(int page, int limit, Integer branchid) {
        PageHelper.startPage(page,limit);
        List<Stafftransfer> all = dao.getAll(branchid);
        PageInfo<Stafftransfer> pageInfo = new PageInfo<Stafftransfer>(all);
        return new TableLayUi(0,"",pageInfo.getTotal(),pageInfo.getList());
    }
}
